//
//  HJJourneyView.m
//  project
//
//  Created by jc on 2019/5/14.
//  Copyright © 2019 健健. All rights reserved.
//

#import "HJJourneyView.h"
#import "YFJourneyModel.h"

@interface HJJourneyView ()
@property (weak, nonatomic) IBOutlet UIView *bgView;
@property (weak, nonatomic) IBOutlet UIImageView *journeyImage;
@property (weak, nonatomic) IBOutlet UILabel *journeyTitle;
@property (weak, nonatomic) IBOutlet UILabel *createTime;
@property (weak, nonatomic) IBOutlet UILabel *journeyTime;
@property (weak, nonatomic) IBOutlet UILabel *startLocation;
@property (weak, nonatomic) IBOutlet UILabel *endLocation;
@property (weak, nonatomic) IBOutlet UIButton *upBtn;

@end
@implementation HJJourneyView

+(instancetype)initJourneyViewWithframe:(CGRect)frame {
    HJJourneyView * view = [[HJJourneyView alloc]init];
    view.frame = frame;
    return view;
}

-(void)show {
    self.alpha = 0;
    self.transform = CGAffineTransformMakeScale(0,0);
    [UIView animateWithDuration:0.5 delay:0 usingSpringWithDamping:0.7 initialSpringVelocity:1 options:UIViewAnimationOptionCurveEaseOut animations:^{
        self.alpha = 1;
        self.transform = CGAffineTransformMakeScale(2.0,2.0);
        self.transform = CGAffineTransformMakeScale(1, 1);
    } completion:^(BOOL finished) {
        self.transform = CGAffineTransformIdentity;
    }];
}
-(void)dismissWithBtn:(void(^)(BOOL isDismiss))complet {
    [UIView animateWithDuration:0.5 delay:0 usingSpringWithDamping:0.7 initialSpringVelocity:1 options:UIViewAnimationOptionCurveEaseOut animations:^{
        self.alpha = 0;
        self.transform = CGAffineTransformMakeScale(0,0);
    } completion:^(BOOL finished) {
        [self removeFromSuperview];
        self.alpha = 1;
        self.transform = CGAffineTransformIdentity;
    }];
    complet(YES);
}
-(instancetype)init {
    if (self == [super init]) {
        self = [[NSBundle mainBundle]loadNibNamed:@"HJJourneyView" owner:nil options:nil].firstObject;
        [self layerSubView];
        @weakify(self)
        [[self.upBtn rac_signalForControlEvents:UIControlEventTouchUpInside]subscribeNext:^(__kindof UIControl * _Nullable x) {
            @strongify(self)
            [self dismissWithBtn:^(BOOL isDismiss) {
                self.cancleClick(isDismiss);
            }];
        }];
    }
    return self;
}
-(void)layerSubView {
    [self setupShadowWithView:self.bgView];
}

-(void)loadData:(YFTripModel *)model {
    self.journeyImage.image = model.wayImage;
    self.journeyTitle.text = model.title;
    self.createTime.text = model.createTime;
    // 起点名称
    self.startLocation.text = model.startTxt;
    // 终点名称
    self.endLocation.text =model.dstTxt;
    // 出行日期和时间
    self.journeyTime.text = [NSString stringWithFormat:@"%@ %@",model.journeyDate,model.journeyTime];
}
@end
